def last_person_number(m, n):
    people = list(range(1, m + 1))
    current_index = 0
    
    for num in range(1, n + 1):
        if num % 7 == 0:
            continue
        else:
            current_index = (current_index + 1) % len(people)
    return people[current_index - 1]

m = int(input())
n = int(input())

result = last_person_number(m, n)
print(result)